﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

public partial class download : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string filename = Request.QueryString["filename"];
        string filepath = Server.MapPath("~/document/") + filename;//路径    
        if (!string.IsNullOrEmpty(filepath))
        {

            FileInfo fileinfo = new FileInfo(filepath);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Content-Disposition", "attachment;filename=" + fileinfo.Name);
            Response.AddHeader("Content-Length", fileinfo.Length.ToString());
            Response.AddHeader("Content-Transfer-Encoding", "binary");
            Response.ContentType = "application/octet-stream";
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
            Response.WriteFile(fileinfo.FullName);
            Response.Flush();
            Response.End();   
        }
        
    }
}